#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QPaintEvent>
#include <QPainter>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QEvent>
#include <QDebug>
#include <QList>
#include <QTimer>
#define DIRECTION_LEFT 1
#define DIRECTION_UP 2
#define DIRECTION_RIGHT 3
#define DIRECTION_DOWN 4

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
public slots:
    void gameLoop();
    void help();

private:
    Ui::MainWindow *ui;
    //鼠标事件
    void mousePressEvent(QMouseEvent *);
    void mouseReleaseEvent(QMouseEvent *);
    void mouseMoveEvent(QMouseEvent* e);
    //键盘事件
    void keyPressEvent(QKeyEvent *evt);
    bool event(QEvent *event);
    void move();
    void stop();
    void start();
    void initial();
    void restart();


protected:
    void paintEvent(QPaintEvent *);
    int GAME_MAP_WIDTH=400;
    int GAME_MAP_HEIGHT=600;
    int RECT_WIDTH=20;
    int RECT_HEIGHT=20;
    int headDirection=DIRECTION_LEFT;
    QList<QPoint> *snakePointList;
    //蛇头
    QPoint headPoint;
    //游戏定时器
    QTimer gameTimer;
    //分数
    qint64 score=0;
    //关
    qint64 stage=10;
    QPoint *food;
    void randFood(int x,int y);
    //Message显示位置和内容
    QString message;
    //
    bool startGame;
};

#endif // MAINWINDOW_H
